import 'package:flutter/material.dart';
import 'pages/Home.dart';
import 'pages/Settings.dart';
import 'pages/Category.dart';

class Tabs extends StatefulWidget {
  final index;

  Tabs({this.index = 0});

  @override
  TabsState createState() {
    return TabsState(this.index);
  }
}

class TabsState extends State<Tabs> {
  int currentIndex = 0;
  List _pagList = [
    Home(),
    Category(),
    Settings(),
  ];

  TabsState(index) {
    this.currentIndex = index;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: new Text('Flutter App'),
      ),
      body: _pagList[this.currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: this.currentIndex,
        onTap: (int index) {
          setState(() {
            this.currentIndex = index;
          });
        },
        items: [
          BottomNavigationBarItem(
            icon: Icon(
              Icons.home,
              size: 30,
            ),
            title: Text("首页"),
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.category,
              size: 30,
            ),
            title: Text("分类"),
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.settings,
              size: 30,
            ),
            title: Text("设置"),
          ),
        ],
      ),
      drawer: Drawer(
        child: MyDrawerList(),
      ),
    );
  }
}

class MyDrawerList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        UserAccountsDrawerHeader(
          accountName: Text("Linux"),
          accountEmail: Text("335951872@qq.com"),
          currentAccountPicture: CircleAvatar(
            backgroundImage: NetworkImage(
                "http://article.fd.zol-img.com.cn/t_s640x2000/g2/M00/07/05/Cg-4WVUrYziIChgdAAC0iNQWfiEAABdYAIvGm8AALSg681.jpg"),
          ),
        ),
        ListTile(
          leading: CircleAvatar(
            child: Icon(Icons.account_circle),
          ),
          title: Text("个人中心"),
        ),
        ListTile(
          leading: CircleAvatar(
            child: Icon(Icons.monetization_on),
          ),
          title: Text("我的钱包"),
        ),
        ListTile(
          leading: CircleAvatar(
            child: Icon(Icons.collections),
          ),
          title: Text("我的收藏"),
        ),
        ListTile(
          leading: CircleAvatar(
            child: Icon(Icons.photo_album),
          ),
          title: Text("我的相册"),
        ),
        ListTile(
          leading: CircleAvatar(
            child: Icon(Icons.folder_shared),
          ),
          title: Text("注册用户"),
          onTap: () {
            Navigator.of(context).pop();
            Navigator.pushNamed(context, "/registerFirst");
          },
        ),
        ListTile(
          leading: CircleAvatar(
            child: Icon(Icons.exit_to_app),
          ),
          title: Text("退出"),
        ),
      ],
    );
  }
}
